<?php

if (!isset($_SERVER['PHP_AUTH_USER']) || !($_SERVER['PHP_AUTH_USER'] == 'admin' && $_SERVER['PHP_AUTH_PW'] == 'agile')) {
    header('WWW-Authenticate: Basic realm="DBU Manager"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Access denied';
    exit();
}

require dirname(__FILE__) . '/init.php';
require dirname(__FILE__) . '/autoload.php';

$updater = new DBU_Updater();
    
if (isset($_GET['controller']) && !empty($_GET['controller'])) {
    $controller = $_GET['controller'];
    require (DB_CONTROLLERS_PATH . $controller . '.php');

    header("Location: index.php");
    die();
}

$tablesDB = (array) $updater->getDbTables();
$tablesFiles = (array) $updater->getFileTables();
$tablesDataFiles = (array) $updater->getFileTablesData();
$tables = array_unique(array_merge($tablesDB, $tablesFiles));
$version = $updater->getVersion();

$messages = DBU_Flash_Messages::instance()->getAll();

require (DB_TEMPLATES_PATH . 'index.php');
DBU_Logger::instance()->reset();
